<template>
  <div class="index-page">
    <!-- 导航栏 -->
    <nav class="navbar">
      <router-link
          to="/index/recommend"
          class="nav-item"
          active-class="active">
        推荐
      </router-link>
      <router-link
          to="/index/category"
          class="nav-item"
          active-class="active">
        分类
      </router-link>
      <router-link
          to="/index/chat"
          class="nav-item"
          active-class="active">
        聊天
      </router-link>
      <router-link
          to="/index/profile"
          class="nav-item"
          active-class="active">
        个人中心
      </router-link>
      <div class="nav-item logout" @click="handleLogout">退出</div>
    </nav>

    <!-- 添加路由视图 -->
    <router-view></router-view>

    <!-- 悬浮按钮 -->
    <div class="fab" @click="handlePost">
      <span>+</span>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    handlePost() {
      this.$router.push('/good/add');
    },
    handleLogout() {
      sessionStorage.removeItem('token');
      this.$router.push('/');
    }
  }
}
</script>


<style scoped>
.index-page {
  position: relative;
  min-height: 100vh;
  background-color: #f5f5f5;
  font-family: 'Segoe UI', 'PingFang SC', sans-serif;
}

.navbar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 56px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: fixed;  /* 改为固定定位 */
  top: 0;           /* 吸附顶部 */
  left: 0;          /* 左侧对齐 */
  right: 0;         /* 右侧对齐 */
  z-index: 1000;    /* 确保在其他内容之上 */
  /* 移除原来的 position: relative */
  /* 保留原有 border-bottom */
  border-bottom: 1px solid #eee;
}

.nav-item {
  padding: 8px 16px;
  font-size: 15px;
  color: #666;
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
  display: flex;
  align-items: center;
}

.nav-item::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 2px;
  background: #00C853;
  transition: all 0.3s ease;
}

.nav-item.active {
  color: #00C853;
  font-weight: 500;
}

.nav-item.active::after {
  left: 0;
  width: 100%;
  transform: translateX(0);
}

.nav-item:hover:not(.active) {
  color: #333;
}

/* 退出按钮样式 */
.logout {
  color: #ff4444 !important;
  cursor: pointer;
  border-radius: 4px;
  padding: 6px 12px;
}

.logout:hover {
  background: rgba(255, 68, 68, 0.1);
}

/* 悬浮按钮样式 */
.fab {
  position: fixed;
  right: 24px;
  bottom: 80px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #00C853 0%, #009624 100%);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 200, 83, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab span {
  color: white;
  font-size: 28px;
  font-weight: 300;
  margin-top: -2px;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 200, 83, 0.4);
}

/* 路由视图区域 */
.router-view {
  padding: 16px;
  min-height: calc(100vh - 112px);
}

/* 导航项分隔线 */
.nav-item:not(:last-child)::before {
  content: '';
  position: absolute;
  right: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 16px;
  background: #eee;
}
</style>